<template>
    <div class="goodslist">
        <router-link :to="'/home/goodsinfo/' + item.id" class="goods-item" v-for="item in goodsList" :key="item.id">
            <div class="box">
                <img :src="item.img_url" alt="">
                <h1 class="title">{{item.title}}</h1>
            </div>
            <div class="infos">
                <p class="price">
                    <span class="now">￥{{item.sell_price}}</span>
                    <span class="old">￥{{item.market_price}}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩余{{item.stock_quantity}}件</span>
                </p>
            </div>
        </router-link>
        <mt-button type="primary" size="large" @click="getMore">加载更多</mt-button>
    </div>
</template>

<script>
import { Toast } from 'mint-ui'
export default {
    data() {
        return {
            pageIndex:1,
            goodsList:[]
        }
    },
    created(){
        this.getGoodsList()
    },
    methods:{
        getGoodsList(){
            this.$http.get('api/getgoods?pageIndex=' + this.pageIndex).then(result => {
                if(result.body.status == 0){
                    this.goodsList = this.goodsList.concat(result.body.message)
                }else{
                    Toast('请求商品列表失败')
                }
            })
        },
        getMore(){
            this.pageIndex ++;
            this.getGoodsList()
        }
    }
}
</script>

<style lang="sass" scoped>
    .goodslist{
        display:flex;
        flex-wrap:wrap;

        .goods-item{
            margin:5px;
            width:47%;
            display:flex;
            flex-direction: column;
            justify-content: space-between;
            border:1px solid #ccc;
            min-height:290px;

            .box{
                position:relative;
                margin:0;
                padding:0;
                img{
                    width:100%;
                }
                h1.title{
                    font-size:14px;
                }
            }
            .infos{
                padding: 5px;
                background-color:#e5e5e5;
            
                .price{
                    margin:0;
                    line-height:30px;
                    span.now{
                        color:red;
                        font-weight:900;
                    }
                    span.old{
                        margin-left:10px;
                        font-size:12px;
                        text-decoration:line-through;
                    }
                }
                .sell{
                    display:flex;
                    justify-content:space-between;
                }
            }
        }
    }
</style>
